home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / xbuscmd / xbuscmd.c < prev    next >
C/C++ Source or Header  |  1992-12-11  |  11KB  |  369 lines

  1. /* 
  2.  * vmelinkcmd.c --
  3.  *
  4.  *    Program for dealing with the Ultranet VME adapter board..
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.3 90/01/12 12:03:36 douglis Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include "sprite.h"
  21. #include "option.h"
  22. #include <stdio.h>
  23. #include <sys/file.h>
  24. #include <fs.h>
  25. #include <status.h>
  26. #include <fmt.h>
  27. #include <ctype.h>
  28. #include <dev/xbus.h>
  29.  
  30. #define    SRC_BUFFER    0x1
  31. #define    DST_BUFFER    0x2
  32.  
  33. /*
  34.  * Variables settable via the command line.
  35.  */
  36. char        *device = "/dev/xbus0";
  37. char*        debugString = NULL;    /* turn debugging on or off? */
  38. Boolean        resetBoards = FALSE;    /* reset the boards? */
  39. char*        rregStr = NULL;
  40. char*        wregStr = NULL;
  41. unsigned int    regValue = 0;
  42. unsigned int    xorSize = 0x1000;
  43. unsigned int    xorDest = 0x0;
  44. unsigned int    xorArray[DEV_XBUS_MAX_XOR_BUFS + 4];
  45. Boolean        doXor = FALSE;
  46. int        whichBuffer = 0;
  47. unsigned int    bufAddr = 0;
  48. unsigned int    bufSize = 0x100;
  49. char*        parityString = NULL;
  50. char        *myname = "xbuscmd";
  51. int        readXorSrcBuffers ();
  52. char*        vmeBoardStr = NULL;
  53. char*        useIntrStatusStr = NULL;
  54.  
  55. unsigned int    stripeUnit = 0x8000;
  56. unsigned int    testStart = 0;
  57. unsigned int    testEnd = 0;
  58. unsigned int    numDisks = 2;
  59. unsigned int    maxNumReq = 10;
  60. Boolean        testStop = FALSE;
  61. Boolean        testPrintStats = FALSE;
  62.  
  63. char    statString[DEV_XBUS_TEST_MAX_STAT_STR+10];
  64.  
  65. Option optionArray[] = {
  66.     {OPT_DOC, NULL, NULL, "Usage: xbuscmd [options]"},
  67.     {OPT_TRUE, "reset", (Address)&resetBoards,
  68.      "Reset the xbus boards."},
  69.     {OPT_STRING, "debug", (Address)&debugString,
  70.      "Turn debugging ON or OFF."},
  71.     {OPT_STRING, "parity", (Address)&parityString,
  72.      "Turn parity checking ON or OFF"},
  73.     {OPT_STRING, "vmeBoard", (Address)&vmeBoardStr,
  74.      "VME link board to lock for accesses."},
  75.     {OPT_STRING, "device", (Address)&device,
  76.      "Set the xbus device."},
  77.     {OPT_STRING, "rreg", (Address)&rregStr,
  78.      "Read an xbus register."},
  79.     {OPT_STRING, "wreg", (Address)&wregStr,
  80.      "Write an xbus register."},
  81.     {OPT_INT, "value", (Address)®Value,
  82.      "Value to use for writing to a register."},
  83.     {OPT_CONSTANT(SRC_BUFFER), "send", (Address)&whichBuffer,
  84.      "Send data over the HIPPI-S bus"},
  85.     {OPT_CONSTANT(DST_BUFFER), "recv", (Address)&whichBuffer,
  86.      "Receive data over the HIPPI-D bus"},
  87.     {OPT_INT, "bufAddr", (Address)&bufAddr,
  88.      "XBUS address of the HIPPI buffer"},
  89.     {OPT_INT, "bufSize", (Address)&bufSize,
  90.      "Size (in bytes) of the HIPPI buffer"},
  91.     {OPT_INT, "xorSize", (Address)&xorSize,
  92.      "Size (in bytes) of the XOR buffers."},
  93.     {OPT_INT, "xorDest", (Address)&xorDest,
  94.      "XOR destination buffer (in XBUS address space)."},
  95.     {OPT_GENFUNC, "xorSrc", (Address)readXorSrcBuffers,
  96.      "XOR source buffer(s) (in XBUS address space)."},
  97.     {OPT_STRING, "useIntrStatus", (Address)&useIntrStatusStr,
  98.      "Turn use of interrupt status ON or OFF."},
  99.     {OPT_INT, "testStart", (Address)&testStart,
  100.      "Start of XBUS memory for overall test."},
  101.     {OPT_INT, "testEnd", (Address)&testEnd,
  102.      "End of XBUS memory for overall test."},
  103.     {OPT_INT, "stripeUnit", (Address)&stripeUnit,
  104.      "Stripe unit size for XBUS overall test."},
  105.     {OPT_INT, "numDisks", (Address)&numDisks,
  106.      "Number of disks to use for XBUS overall test."},
  107.     {OPT_INT, "maxNumReq", (Address)&maxNumReq,
  108.      "Maximum number of requests to do."},
  109.     {OPT_TRUE, "testStop", (Address)&testStop,
  110.      "Stop the XBUS overall test."},
  111.     {OPT_TRUE, "testStats", (Address)&testPrintStats,
  112.      "Print the statistics for the last XBUS overall test."},
  113. };
  114.  
  115. /*----------------------------------------------------------------------
  116.  *
  117.  * readXorSrcBuffers --
  118.  *
  119.  *    Option parser to read an unknown number of source buffers from
  120.  *    the command line.  It will allow more than one buffer to go
  121.  *    with the -xorSrc option.
  122.  *
  123.  *----------------------------------------------------------------------
  124.  */
  125. static
  126. int
  127. readXorSrcBuffers (optStr, argc, argv)
  128. char*    optStr;
  129. int    argc;
  130. char**    argv;
  131. {
  132.     int        numBufs, i;
  133.     char*    c;
  134.  
  135.     for (numBufs = 0; numBufs < argc; numBufs++) {
  136.     xorArray[numBufs+3] = strtoul (argv[numBufs], &c, 0);
  137.     if (c == argv[numBufs]) {
  138.         break;
  139.     }
  140.     }
  141.     if (numBufs == 0) {
  142.     printf ("%s: must have at least one source buffer for %s.\n",
  143.         myname, optStr);
  144.     Opt_PrintUsage(myname, optionArray, Opt_Number (optionArray));
  145.     exit(1);
  146.     }
  147.  
  148.     xorArray[0] = numBufs;
  149.     doXor = TRUE;
  150.     for (i = numBufs; i < argc; i++) {
  151.     argv[i-numBufs] = argv[i];
  152.     }
  153.     return (argc - numBufs);
  154. }
  155.  
  156. /*
  157.  *----------------------------------------------------------------------
  158.  *
  159.  * main --
  160.  *
  161.  *    Parse the arguments and call the correct procedure.
  162.  *
  163.  * Results:
  164.  *    None.
  165.  *
  166.  * Side effects:
  167.  *    The state of the xbus board may be modified.
  168.  *
  169.  *----------------------------------------------------------------------
  170.  */
  171.  
  172. int
  173. main(argc, argv)
  174.     int        argc;
  175.     char    *argv[];
  176. {
  177.     int            argsLeft;
  178.     int            fd = -1;
  179.     unsigned int    regNum;
  180.     char        *c;
  181.     ReturnStatus    status;
  182.     extern int        errno;
  183.  
  184.     argsLeft = Opt_Parse(argc, argv, optionArray, Opt_Number (optionArray), 0);
  185.     if ((argsLeft > 1) || (argc < 2)) {
  186.     Opt_PrintUsage(myname, optionArray, Opt_Number (optionArray));
  187.     exit(1);
  188.     }
  189.  
  190.     if ((wregStr != NULL) && (rregStr != NULL)) {
  191.     printf ("%s: may not both read and write a register.\n");
  192.     Opt_PrintUsage(myname, optionArray, Opt_Number (optionArray));
  193.     exit(1);
  194.     } else if (wregStr != NULL) {
  195.     regNum = strtoul (wregStr, &c, 0);
  196.     } else if (rregStr != NULL) {
  197.     regNum = strtoul (rregStr, &c, 0);
  198.     }
  199.  
  200.     if (((wregStr != NULL) + (rregStr != NULL) + (whichBuffer != 0) +
  201.      (parityString != NULL) + (doXor == TRUE) + (testStart != testEnd) +
  202.      (vmeBoardStr != NULL) + (useIntrStatusStr != NULL) +
  203.      (testStop == TRUE) + (testPrintStats == TRUE)) > 1) {
  204.     printf ("%s: one thing at a time, please!\n", myname);
  205.     Opt_PrintUsage(myname, optionArray, Opt_Number (optionArray));
  206.     exit(1);
  207.     }    
  208.  
  209.     if ((fd = open (device, O_RDONLY, 0666)) < 0) {
  210.     printf ("%s: Error 0x%x opening %s\n", myname, errno, device);
  211.     Opt_PrintUsage(myname, optionArray, Opt_Number (optionArray));
  212.     exit (1);
  213.     }
  214.  
  215.     if (debugString != NULL) {
  216.     if (!strcasecmp (debugString, "on")) {
  217.         status = Fs_IOControl (fd, IOC_XBUS_DEBUG_ON, 0, NULL, 0, NULL);
  218.     } else if (!strcasecmp (debugString, "off")) {
  219.         status = Fs_IOControl (fd, IOC_XBUS_DEBUG_OFF,0, NULL, 0, NULL);
  220.     } else {
  221.         printf ("%s: -debug requires ON or OFF, not %s!\n", myname,
  222.             debugString);
  223.         exit (1);
  224.     }
  225.     if (status != SUCCESS) {
  226.         printf ("%s: modifying debug flag returned 0x%x\n",myname,status);
  227.     }
  228.     }
  229.  
  230.     if (resetBoards) {
  231.     status = Fs_IOControl (fd, IOC_XBUS_RESET, 0, NULL, 0, NULL);
  232.     if (status != SUCCESS) {
  233.         printf ("%s: XBUS_RESET returned 0x%x\n", myname, status);
  234.     }
  235.     }
  236.     if (vmeBoardStr != NULL) {
  237.     int    vmeBoard;
  238.  
  239.     vmeBoard = strtol (vmeBoardStr, NULL, 0);
  240.     status = Fs_IOControl (fd, IOC_XBUS_LOCK_VME, sizeof (vmeBoard),
  241.                    (Address)&vmeBoard, 0, NULL);
  242.     if (status != SUCCESS) {
  243.         printf ("%s: couldn't set VME board to lock to %d.\n",
  244.             myname, vmeBoard);
  245.     }
  246.     } else if (useIntrStatusStr != NULL) {
  247.     int        oldUse, newUse;
  248.     if (!strcasecmp (useIntrStatusStr, "on")) {
  249.         newUse = TRUE;
  250.     } else if (!strcasecmp (useIntrStatusStr, "off")) {
  251.         newUse = FALSE;
  252.     } else {
  253.         printf ("%s: -useIntrStatus requires ON or OFF, not %s!\n", myname,
  254.             useIntrStatusStr);
  255.         exit (1);
  256.     }
  257.     status = Fs_IOControl (fd, IOC_XBUS_USE_INTR_STATUS, sizeof (newUse),
  258.                    (Address)&newUse, sizeof (oldUse),
  259.                    (Address)&oldUse);
  260.     if (status != SUCCESS) {
  261.         printf ("%s: turning interrupt status use %s returned 0x%x\n",
  262.             myname, useIntrStatusStr, status);
  263.     } else {
  264.         printf ("%s: interrupt status use was %s, is now %s.\n", myname,
  265.             oldUse ? "ON" : "OFF", useIntrStatusStr);
  266.     }
  267.     } else if (parityString != NULL) {
  268.     int    parity;
  269.  
  270.     if (!strcasecmp (parityString, "on")) {
  271.         parity = TRUE;
  272.     } else if (!strcasecmp (parityString, "off")) {
  273.         parity = FALSE;
  274.     } else {
  275.         printf ("%s: -parity requires ON or OFF, not %s!\n", myname,
  276.             parityString);
  277.         exit (1);
  278.     }
  279.     status = Fs_IOControl (fd, IOC_XBUS_CHECK_PARITY, sizeof (parity),
  280.                    (Address)&parity, 0, NULL);
  281.     if (status != SUCCESS) {
  282.         printf ("%s: turning parity %s returned 0x%x\n", myname,
  283.             parityString, status);
  284.     }
  285.     } else if ((rregStr != NULL) || (wregStr != NULL)) {
  286.     DevXbusRegisterAccess acc;
  287.     int    iocNum;
  288.  
  289.     acc.registerNum = regNum;
  290.     acc.value = regValue;
  291.     iocNum = (rregStr != NULL) ? IOC_XBUS_READ_REG : IOC_XBUS_WRITE_REG;
  292.     status = Fs_IOControl (fd, iocNum, sizeof(acc),&acc,sizeof(acc),&acc);
  293.     if (status != SUCCESS) {
  294.         printf ("%s: register access returned 0x%x\n", myname, status);
  295.     } else {
  296.         printf ("Register 0x%03x = 0x%08x\n", acc.registerNum, acc.value);
  297.     }
  298.     } else if ((testStart != 0) && (testEnd != 0)) {
  299.     unsigned int    testArgs[5];
  300.  
  301.     testArgs[0] = testStart;
  302.     testArgs[1] = testEnd;
  303.     testArgs[2] = stripeUnit;
  304.     testArgs[3] = numDisks;
  305.     testArgs[4] = maxNumReq;
  306.     status = Fs_IOControl (fd, IOC_XBUS_TEST_START, sizeof (testArgs),
  307.                    testArgs, 0, NULL);
  308.     if (status != SUCCESS) {
  309.         printf ("%s: unable to start XBUS test (status = 0x%x).\n", myname,
  310.             status);
  311.     }
  312.     } else if (testStop) {
  313.     status = Fs_IOControl (fd, IOC_XBUS_TEST_STOP, 0, NULL, 0, NULL);
  314.     if (status != SUCCESS) {
  315.         printf ("%s: unable to stop XBUS test (status = 0x%x).\n", myname,
  316.             status);
  317.     }
  318.     } else if (testPrintStats) {
  319.     status = Fs_IOControl (fd, IOC_XBUS_TEST_STATS, 0, NULL,
  320.                    sizeof (statString), statString);
  321.     if (status != SUCCESS) {
  322.         printf ("%s: unable to print XBUS test stats (status = 0x%x).\n",
  323.             myname, status);
  324.     } else {
  325.         printf ("Here is the statistics string:\n");
  326.         puts (statString);
  327.     }
  328.     } else if (whichBuffer != 0) {
  329.     DevXbusRegisterAccess acc;
  330.     unsigned int reg;
  331.  
  332.     reg = (whichBuffer == SRC_BUFFER) ? DEV_XBUS_REG_HIPPIS_CTRL_FIFO :
  333.         DEV_XBUS_REG_HIPPID_CTRL_FIFO;
  334.     acc.registerNum = reg;
  335.     acc.value = bufSize >> 2;
  336.     status = Fs_IOControl (fd, IOC_XBUS_WRITE_REG, sizeof(acc),
  337.                    &acc, sizeof(acc), &acc);
  338.     if (status != SUCCESS) {
  339.         printf ("%s: unable to push extent (error 0x%x).\n",myname,status);
  340.     } else {
  341.         acc.registerNum = reg;
  342.         acc.value = bufAddr >> 2;
  343.         status = Fs_IOControl (fd, IOC_XBUS_WRITE_REG, sizeof(acc),&acc,
  344.                    sizeof(acc), &acc);
  345.         if (status != SUCCESS) {
  346.         printf ("%s: unable to push buffer address (error 0x%x).\n",
  347.             myname, status);
  348.         } else {
  349.         printf ("%s: queued 0x%x byte buffer at 0x%x for %s.\n",
  350.             myname, bufSize, bufAddr,
  351.             ((whichBuffer == SRC_BUFFER) ? "hippis" : "hippid"));
  352.         }
  353.     }
  354.     } else if (doXor) {
  355.     int    nbufs = xorArray[0];
  356.  
  357.     xorArray[1] = xorSize;
  358.     xorArray[2] = xorDest;
  359.     status = Fs_IOControl (fd, IOC_XBUS_DO_XOR,
  360.                    (nbufs + 3) * sizeof (xorArray[0]),
  361.                    xorArray, 0, NULL);
  362.     if (status != SUCCESS) {
  363.         printf ("%s: doing XOR returned 0x%x\n", myname, status);
  364.     }
  365.     }
  366.  
  367.     close (fd);
  368. }
  369.